package com.swa99ylum.pjv.sample.s04_others.s0410;

import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONPath;
import com.swa99ylum.pjv.sample.FileUtils;
import com.swa99ylum.pjv.util.PJVUtils;

public class PerformanceTest3 {
	

	public static void main(String[] args) {
		long begin = new Date().getTime(); 
		PerformanceTest3 p = new PerformanceTest3();
		p.foo();
		
		long end = new Date().getTime();
		System.out.println("总耗时：" + (end-begin));
	}
	
	@SuppressWarnings("unchecked")
	public void foo() {
		//step1、获取 json
//		String filePath = Test1.class.getResource("json_0410_30.txt").getPath();
		String filePath = Test1.class.getResource("json_0410.txt").getPath();
		
		String json = null;
		try {
			json = FileUtils.getFileContent(filePath);
		} catch (Exception e) {
			System.err.println("从 文件中，读取 json 有误");
		}
		
		Object obj = JSON.parse(json);
		
		//step2、解析 json
		List<Object> aaa1 = (List<Object>) JSONPath.read(json, "$.data.request");
		String[] aaa2 = new String[]{"matnr", "werks", "zdate", "labst", "speme"};
		
		for(int i=0; i<=aaa1.size()-1; i++) {
			
			for (String string : aaa2) {
				long begin = new Date().getTime();
				
				String[] nodePath = new String[]{"$", "data", "request["+i+"]", string};
				String path = StringUtils.join(nodePath, ".");
				
				//System.out.println(path + " => " + JsonPath.read(json, path));
//				System.out.println(path + " => " + objI.get(string));
				System.out.println(path + " => " + PJVUtils.getNodeValue(obj, nodePath));
				
				long end = new Date().getTime();
				System.out.println(end-begin);
			}
			
		}
		
		
//		//step2、解析 json
//		@SuppressWarnings("unchecked")
//		List<Map> aaa1 = (List<Map>) JSONPath.read(json, "$.data.request");
//		for(int i=0; i<aaa1.size()-1; i++) {
//			Map map = aaa1.get(i);
//			System.out.println("==================> " + i);
//			System.out.println(map.get("matnr"));
//			System.out.println(map.get("werks"));
//			System.out.println(map.get("zdate"));
//			System.out.println(map.get("labst"));
//			System.out.println(map.get("speme"));
////			long begin = new Date().getTime();
////			String path = "$.data.request["+i+"]." + string;
////			System.out.println(path);
////			JsonPath.read(json, path);
////			long end = new Date().getTime();
////			System.out.println(string);
//		}
//		String[] aaa2 = new String[]{"matnr", "werks", "zdate", "labst", "speme"};
//		
////		for(int i=0; i<aaa1.size()-1; i++) {
////			
////			for (String string : aaa2) {
////				long begin = new Date().getTime();
////				String path = "$.data.request["+i+"]." + string;
////				System.out.println(path);
////				JsonPath.rread(json, path);
////				long end = new Date().getTime();
////				System.out.println(end-begin);
////			}
////			
////			
////			
////		}
	
	}
}
